"""The ExportPanel module contains the ExportPanel class, which builds the GUI for the Export tab"""

import wx

class ExportPanel(wx.Panel):
    def __init__(self, parent, id, plgen, settings):
        self.plgen = plgen
        self.settings = settings

        wx.Panel.__init__(self, parent, wx.ID_ANY)

        self.tagtext = wx.StaticText(self, -1, "Enter a tag: (Leave blank to select all files)", wx.Point(10,1))
        self.tagbox = wx.TextCtrl(self, 20, "", wx.Point(10,20), wx.Size(140,-1))

        self.formattext = wx.StaticText(self, -1, "Pick a format", wx.Point(10, 50))
        self.formatbox = wx.ComboBox(self, -1, settings["exportFormats"][0], wx.Point(10,70), wx.DefaultSize, settings["exportFormats"], wx.CB_DROPDOWN)

        self.formattext = wx.StaticText(self, -1, "Pick a lowest rating", wx.Point(10, 100))
        self.formatbox = wx.ComboBox(self, -1, settings["ratings"][0], wx.Point(10,120), wx.DefaultSize, settings["ratings"], wx.CB_DROPDOWN)


        self.exportButton = wx.Button(self, -1, "Export playlist", pos=(100, 170))
        self.Bind(wx.EVT_BUTTON, self.export, self.exportButton)

    def export(self, event):
        format = self.settings["exportFormats"][int(self.formatbox.GetValue()) - 1]
        dlg = wx.FileDialog(self, "Open video file...", self.plgen.getDirectory(), style=wx.SAVE, wildcard=self.settings["wildcards"][format])
        if dlg.ShowModal() == wx.ID_OK:
            self.plgen.export(self.tagbox.GetValue(), format, dlg.GetPath())
        dlg.Destroy()